package com.example.demo.service;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-11-27
 * Time: 22:57
 */


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * 这个类用于发送邮件
 */
@Service
public class SendMailService {
    @Autowired
    private JavaMailSender javaMailSender;

    //发送人和配置文件中一致
    @Value("${spring.mail.username}")
    private String from;
//    //接收人
//    private String to = "test@126.com";
//    //标题
//    private static String subject = "测试邮件";
//    //正文
//    private String context = "测试邮件正文内容：我想给陈老老老板一键三连";

    public void sendMail(String toUser,String title,String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(toUser);
        message.setSubject(title);
        message.setText(content);
        javaMailSender.send(message);
    }
}
